package com.huangpeng.designmodel.proxyDutyChain;

/**
 * @Author hp
 * @Title
 * @Package
 * @Date 2021/12/28 15:43
 * @Description 测试类
 * @Version 1.0
 */
public class Test {
    public static void main(String[] args) {
        /*HelloService target = new HelloServiceImpl();
        Interceptor transactionInterceptor = new TransactionInterceptor();
        HelloService targetProxy = (HelloService) HWInvocationHandler.wrap(target,transactionInterceptor);
        targetProxy.sayHello();*/

        /*HelloService target = new HelloServiceImpl();
        Interceptor transactionInterceptor = new TransactionInterceptor();
        Interceptor logInterceptor = new LogInterceptor();
        //把事务拦截器插入到目标类中
        target = (HelloService) transactionInterceptor.plugin(target);
        target = (HelloService) logInterceptor.plugin(target);
        target.sayHello();*/

        HelloService target = new HelloServiceImpl();
        Interceptor transactionInterceptor = new TransactionInterceptor();
        Interceptor logInterceptor = new LogInterceptor();
        InterceptorChain interceptorChain = new InterceptorChain();
        interceptorChain.addInterceptor(transactionInterceptor);
        interceptorChain.addInterceptor(logInterceptor);
        target = (HelloService) interceptorChain.pluginAll(target);
        target.sayHello();
    }
}
